package com.mervin.patterns.factory.simplefactory;

import com.mervin.patterns.factory.Apple;
import com.mervin.patterns.factory.BadFruitException;
import com.mervin.patterns.factory.Fruit;
import com.mervin.patterns.factory.Pear;

/***************************************
 * @Auther: mervin
 * @Date: 2020-04-17 00:15
 * @Description: 简单水果工厂
 ***************************************/
public class SimpleFruitFactory {

    public static Fruit createFruit(String fruitType) throws BadFruitException {
        if (fruitType == null) {
            throw new BadFruitException("ruit request must require !");
        }
        fruitType = fruitType.toLowerCase();
        switch (fruitType){
            case "apple":
                return new Apple();
            case "pear":
                return new Pear();
            default:
                throw new BadFruitException("Bad fruit request...");
        }
    }
}
